//
//  ReviewDetailsPage_Vm.swift
//  MikerShop
//
//  Created by eme on 2016/12/1.
//  Copyright © 2016年 eme. All rights reserved.
//

import RxSwift
import Result
import SwiftyJSON
import NetWorkCore
import ModelProtocol
import BrandonCore
/*
 owner:cy
 update:2016年12月01日11:30:063
 info: 审核详情 的viewmodel
 */
class ReviewDetailsPage_Vm {
    
    /*
     接收返回的数据
     */
    let glShopItemSubject = PublishSubject<GlShopModel>()
    /*
     通用设置
     */
    /// 表示正在加载更多种..
    let loading : Observable<Bool>
    /// 表示正在刷新中
    let refreshing = Variable(false)
    /// 保存错误
    let error = PublishSubject<MikerError>()
    private let disposeBag = DisposeBag()
    
    init(refreshTriger: Observable<String>) {

        let requestIndicator = ActivityIndicator()
        self.loading = requestIndicator.asObservable()
        refreshTriger
            .map{spid in UserApi.getshop(spid: spid) }
            .emeRequestApiForObj(GlShopModel.self,activityIndicator: requestIndicator)
            .subscribe(onNext: { [unowned self] (result) in
                switch result {
                case .success(let data):
                    self.glShopItemSubject.onNext(data)
                case .failure(let error):
                    self.error.onNext(error)
                }
            })
            .addDisposableTo(disposeBag)
    }
    
}
